package com.mini.vo;

import com.mini.util.BusinessUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.FieldNameConstants;

import java.util.Objects;
import java.util.UUID;

@Data
@FieldNameConstants
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel(value = "数据看板对象-格式化字符串-前端使用")
public class KanbanDataFormatVO {

    @ApiModelProperty(value = "列表的唯一id,前端使用的")
    private String unionKey = UUID.randomUUID().toString();
    private String unionName;

    @ApiModelProperty(value = "维度显示的字段，对应维度显示的第一级")
    private String dataName;

    private Long groupId;
    private Long deptId;
    private Long studioId;
    private Long skuId;
    private Long classId;
    private Long teacherId;
    @ApiModelProperty(value = "运营组名称")
    private String groupName;
    @ApiModelProperty(value = "运营部名称")
    private String deptName;
    @ApiModelProperty(value = "工作室名称")
    private String studioName;
    @ApiModelProperty(value = "sku名称")
    private String skuName;
    @ApiModelProperty(value = "班次")
    private String className;
    @ApiModelProperty(value = "运营专员")
    private String teacherName;


    @ApiModelProperty(value = "小课订单总数")
    private Long orderCount;

//    //状态字段-因为还tmd要显示百分数，所以定义成string
//    @ApiModelProperty(value = "加微率")
//    private String states;
//    @ApiModelProperty(value = "加群率")
//    private String addWechatGroupState;
//    @ApiModelProperty(value = "入学测试率")
//    private String admissionTestState;
//    @ApiModelProperty(value = "领取优惠劵率")
//    private String getCoupon;
//    @ApiModelProperty(value = "关注公众号率")
//    private String followPublic;

    @ApiModelProperty(value = "加微人数 ")
    private Long statesCount;
    @ApiModelProperty(value = "加群人数")
    private Long addWechatGroupStateCount;
    @ApiModelProperty(value = "入学测试人数")
    private Long admissionTestStateCount;
    @ApiModelProperty(value = "领取优惠劵人数")
    private Long getCouponCount;
    @ApiModelProperty(value = "关注公众号人数")
    private Long followPublicCount;
    @ApiModelProperty(value = "[20200713]未支付订单数: 0默认已支付 1未支付")
    private Long unPayZeroStateCount;


    @ApiModelProperty(value = "[大课]一阶大课流水（不包含未关联到尾款的定金）")
    private Float bigLessonPrice;
    @ApiModelProperty(value = "[大课]一阶大课成单数")
    private Integer bigLessonCount;
    @ApiModelProperty(value = "[大课]一阶大课退款金额")
    private Float bigLessonRefundFee;

    @ApiModelProperty(value = "[20200721][大课]一阶大课流水(带纯定金)（包含未关联尾款的定金）")
    private Float bigLessonPriceTotal;
    @ApiModelProperty(value = "[20200721][大课]一阶定金单数")
    private Integer bigLessonDepositCount;


    @ApiModelProperty(value = "[大课]一阶有赞流水")
    private Float youzanFee;
    @ApiModelProperty(value = "[大课]一阶有赞退款")
    private Float youzanRefundFee;
    @ApiModelProperty(value = "[大课]一阶有赞成单数")
    private Integer youzanCount;

    @ApiModelProperty(value = "[大课]一阶直播带货流水")
    private Float xcxFee;
    @ApiModelProperty(value = "[大课]直播带货退款")
    private Float xcxRefundFee;
    @ApiModelProperty(value = "[大课]一阶直播带货成单数")
    private Integer xcxCount;

    @ApiModelProperty(value = "[大课]归属未关联的订单数")
    private Integer unRefBigLessonCount;
    @ApiModelProperty(value = "[大课]归属未关联的流水")
    private Float unRefBigLessonPrice;
    @ApiModelProperty(value = "[大课]归属未关联的订单数-小程序")
    private Integer unRefXcxCount;
    @ApiModelProperty(value = "[大课]归属未关联的流水-小程序")
    private Float unRefXcxFee;
    @ApiModelProperty(value = "[大课]归属未关联的订单数-有赞")
    private Integer unRefYouzanCount;
    @ApiModelProperty(value = "[大课]归属未关联的流水-有赞")
    private Float unRefYouzanFee;

    @ApiModelProperty(value = "[20200721][大课]大课总流水（包含未关联尾款的定金）")
    private Float unRefBigLessonPriceTotal;
    @ApiModelProperty(value = "[20200721][大课]定金单数")
    private Integer unRefBigLessonDepositCount;

//    @ApiModelProperty(value = "销转 = 大课订单数/小课订单数")
//    private Float saleTransRate;


//
//    @ApiModelProperty(value = "[出勤][展示列]总出勤状态/率")
//    private String attnAttn;
//    @ApiModelProperty(value = "[出勤][展示列]直播出勤状态/率")
//    private String attnAttnLive;
//    @ApiModelProperty(value = "[出勤][展示列]点播出勤状态/率")
//    private String attnAttnVod;
//
//    @ApiModelProperty(value = "[出勤][展示列]直播完课率状态/率")
//    private String attnFinishLive;
//    @ApiModelProperty(value = "[出勤][展示列]总完课状态/率")
//    private String attnFinish;
//
//    @ApiModelProperty(value = "[出勤][展示列]总足课率")
//    private String attnFull;
//    @ApiModelProperty(value = "[出勤][展示列]直播足课率")
//    private String attnFullLive;

    @ApiModelProperty(value = "[出勤]应出勤人数：课节总数")
    private Long attnCourseCount;

    @ApiModelProperty(value = "[出勤]总出勤人数")
    private Long attnAttnCount;
    @ApiModelProperty(value = "[出勤]直播出勤人数")
    private Long attnAttnLiveCount;
    @ApiModelProperty(value = "[出勤]点播出勤人数")
    private Long attnAttnVodCount;
    @ApiModelProperty(value = "[出勤]直播完课人数")
    private Long attnFinishLiveCount;
    @ApiModelProperty(value = "[出勤]总完课人数")
    private Long attnFinishCount;

    @ApiModelProperty(value = "[出勤]应出勤时长")
    private Long attnTotalDuration;
    @ApiModelProperty(value = "[出勤]直播出勤时长")
    private Long attnFullLiveDuration;
    @ApiModelProperty(value = "[出勤]总出勤时长")
    private Long attnFullDuration;

    @ApiModelProperty(value = "[出勤][展示]应出勤时长-单位分，注意！因为前端展示，所以这个值已经*orderCount了")
    private String attnTotalDurationMinute;
    @ApiModelProperty(value = "[出勤][展示]直播出勤时长-单位分")
    private String attnFullLiveDurationMinute;
    @ApiModelProperty(value = "[出勤][展示]总出勤时长-单位分")
    private String attnFullDurationMinute;


    @ApiModelProperty(value = "[大课]二阶大课成单数")
    private Integer secBigLessonCount;
    @ApiModelProperty(value = "[大课]二阶定金单数")
    private Integer secBigLessonDepositCount;
    @ApiModelProperty(value = "[大课]二阶大课流水（不包含未关联到尾款的定金）")
    private Float secBigLessonPrice;
    @ApiModelProperty(value = "[大课]二阶大课总流水(带纯定金)（包含未关联尾款的定金）")
    private Float secBigLessonPriceTotal;
    @ApiModelProperty(value = "[大课]二阶大课退款")
    private Float secBigLessonRefundFee;
    @ApiModelProperty(value = "[大课]二阶有赞成单数")
    private Integer secYouzanCount;
    @ApiModelProperty(value = "[大课]二阶有赞流水")
    private Float secYouzanFee;
    @ApiModelProperty(value = "[大课]二阶有赞退款")
    private Float secYouzanRefundFee;
    @ApiModelProperty(value = "[大课]二阶直播带货成单数")
    private Integer secXcxCount;
    @ApiModelProperty(value = "[大课]二阶直播带货流水")
    private Float secXcxFee;
    @ApiModelProperty(value = "[大课]二阶直播带货退款")
    private Float secXcxRefundFee;


//    public String getAttnTotalDurationMinute() {
//        if(getAttnTotalDuration() != null ){
//            attnTotalDurationMinute = BusinessUtil.durationFormat(getAttnTotalDuration() );
//        }
//        return attnTotalDurationMinute;
//    }
//
//    public String getAttnFullLiveDurationMinute() {
//        if(getAttnFullLiveDuration() != null){
//            attnFullLiveDurationMinute = BusinessUtil.durationFormat(getAttnFullLiveDuration());
//        }
//        return attnFullLiveDurationMinute;
//    }
//
//    public String getAttnFullDurationMinute() {
//        if(getAttnFullDuration() != null){
//            attnFullDurationMinute = BusinessUtil.durationFormat(getAttnFullDuration());
//        }
//
//        return attnFullDurationMinute;
//    }


    //状态字段-因为还tmd要显示百分数，所以定义成string
    @ApiModelProperty(value = "加微率")
    private String states;
    @ApiModelProperty(value = "加群率")
    private String addWechatGroupState;
    @ApiModelProperty(value = "入学测试率")
    private String admissionTestState;
    @ApiModelProperty(value = "领取优惠劵率")
    private String getCoupon;
    @ApiModelProperty(value = "关注公众号率")
    private String followPublic;
    @ApiModelProperty(value = "[20200713]未支付0元单标识: 0默认已支付 1未支付")
    private String unPayZeroState;


    @ApiModelProperty(value = "一阶销转 = 大课订单数/小课订单数")
    private String saleTransRate;


    @ApiModelProperty(value = "[出勤][展示列]总出勤状态/率")
    private String attnAttn;
    @ApiModelProperty(value = "[出勤][展示列]直播出勤状态/率")
    private String attnAttnLive;
    @ApiModelProperty(value = "[出勤][展示列]点播出勤状态/率")
    private String attnAttnVod;

    @ApiModelProperty(value = "[出勤][展示列]直播完课率状态/率")
    private String attnFinishLive;
    @ApiModelProperty(value = "[出勤][展示列]总完课状态/率")
    private String attnFinish;

    @ApiModelProperty(value = "[出勤][展示列]总足课率")
    private String attnFull;
    @ApiModelProperty(value = "[出勤][展示列]直播足课率")
    private String attnFullLive;


    @ApiModelProperty(value = "[大课]总大课成单数")
    private Integer totalBigLessonCount;
    @ApiModelProperty(value = "[大课]总定金单数")
    private Integer totalBigLessonDepositCount;
    @ApiModelProperty(value = "[大课]总大课流水（不包含未关联到尾款的定金）")
    private Float totalBigLessonPrice;
    @ApiModelProperty(value = "[大课]总大课流水(带纯定金)（包含未关联尾款的定金）")
    private Float totalBigLessonPriceTotal;
    @ApiModelProperty(value = "[大课]总大课退款")
    private Float totalBigLessonRefundFee;
    @ApiModelProperty(value = "[大课]总有赞成单数")
    private Integer totalYouzanCount;
    @ApiModelProperty(value = "[大课]总有赞流水")
    private Float totalYouzanFee;
    @ApiModelProperty(value = "[大课]总有赞退款")
    private Float totalYouzanRefundFee;
    @ApiModelProperty(value = "[大课]总直播带货成单数")
    private Integer totalXcxCount;
    @ApiModelProperty(value = "[大课]总直播带货流水")
    private Float totalXcxFee;


    public void fillData() {
        this.unionKey = UUID.randomUUID().toString();
        this.addWechatGroupState = BusinessUtil.divisionResultPercent(getAddWechatGroupStateCount(), getOrderCount());
        this.admissionTestState = BusinessUtil.divisionResultPercent(getAdmissionTestStateCount(), getOrderCount());
        this.attnAttn = BusinessUtil.divisionResultPercent(getAttnAttnCount(), getOrderCount());
        this.attnAttnLive = BusinessUtil.divisionResultPercent(getAttnAttnLiveCount(), getOrderCount());
        this.attnAttnVod = BusinessUtil.divisionResultPercent(getAttnAttnVodCount(), getOrderCount());
        this.attnFinish = BusinessUtil.divisionResultPercent(getAttnFinishCount(), getOrderCount());
        this.attnFinishLive = BusinessUtil.divisionResultPercent(getAttnFinishLiveCount(), getOrderCount());
        this.attnFull = BusinessUtil.divisionResultPercent(getAttnFullDuration(), getAttnTotalDuration());
        this.attnFullLive = BusinessUtil.divisionResultPercent(getAttnFullLiveDuration(), getAttnTotalDuration());
        this.attnFullLiveDurationMinute = BusinessUtil.durationFormat(getAttnFullLiveDuration());
        this.attnTotalDurationMinute = BusinessUtil.durationFormat(getAttnTotalDuration());
        this.followPublic = BusinessUtil.divisionResultPercent(getFollowPublicCount(), getOrderCount());
        this.getCoupon = BusinessUtil.divisionResultPercent(getGetCouponCount(), getOrderCount());
        this.states = BusinessUtil.divisionResultPercent(getStatesCount(), getOrderCount());
        this.attnFullDurationMinute = BusinessUtil.durationFormat(getAttnFullDuration());
        this.totalBigLessonCount = BusinessUtil.add(getBigLessonCount(), getSecBigLessonCount());
        this.totalBigLessonDepositCount = BusinessUtil.add(getBigLessonDepositCount(), getSecBigLessonDepositCount());
        this.totalBigLessonPrice = BusinessUtil.add(getBigLessonPrice(), getSecBigLessonPrice());
        this.totalBigLessonPriceTotal = BusinessUtil.add(getBigLessonPriceTotal(), getSecBigLessonPriceTotal());
        this.totalBigLessonRefundFee = BusinessUtil.add(getBigLessonRefundFee(), getSecBigLessonRefundFee());
        this.totalYouzanCount = getYouzanCount();
        this.totalYouzanFee = BusinessUtil.add(getYouzanFee(), getSecYouzanFee());
        this.totalYouzanRefundFee = BusinessUtil.add(getYouzanRefundFee(), getSecYouzanRefundFee());
        this.totalXcxCount = BusinessUtil.add(getXcxCount(), getSecXcxCount());
        this.totalXcxFee = BusinessUtil.add(getXcxFee(), getSecXcxFee());
        this.saleTransRate = BusinessUtil.divisionResultPercent(this.bigLessonCount, this.orderCount);


    }

    public void extractBigOrder(KanbanDataFormatVO big) {
        this.bigLessonCount = big.bigLessonCount;
        this.bigLessonDepositCount = big.bigLessonDepositCount;
        this.bigLessonPrice = big.bigLessonPrice;
        this.bigLessonPriceTotal = big.bigLessonPriceTotal;
        this.bigLessonRefundFee = big.bigLessonRefundFee;
        this.saleTransRate = big.saleTransRate;
        this.secBigLessonCount = big.secBigLessonCount;
        this.secBigLessonDepositCount = big.secBigLessonDepositCount;
        this.secBigLessonPrice = big.secBigLessonPrice;
        this.secXcxCount = big.secXcxCount;
        this.secXcxFee = big.secXcxFee;
        this.secBigLessonPriceTotal = big.secBigLessonPriceTotal;
        this.secXcxRefundFee = big.secXcxRefundFee;
        this.secYouzanCount = big.secYouzanCount;
        this.secYouzanFee = big.secYouzanFee;
        this.secYouzanRefundFee = big.secYouzanRefundFee;
        this.secBigLessonRefundFee = big.secBigLessonRefundFee;
        this.totalBigLessonCount = big.totalBigLessonCount;
        this.totalBigLessonDepositCount = big.totalBigLessonDepositCount;
        this.totalBigLessonPrice = big.totalBigLessonPrice;
        this.totalXcxCount = big.totalXcxCount;
        this.totalXcxFee = big.totalXcxFee;
        this.totalBigLessonPriceTotal = big.totalBigLessonPriceTotal;
        this.totalBigLessonRefundFee = big.totalBigLessonRefundFee;
        this.totalYouzanCount = big.totalYouzanCount;
        this.totalYouzanRefundFee = big.totalYouzanRefundFee;
        this.totalYouzanFee = big.totalYouzanFee;
        this.unRefBigLessonCount = big.unRefBigLessonCount;
        this.unRefBigLessonDepositCount = big.unRefBigLessonDepositCount;
        this.unRefBigLessonPrice = big.unRefBigLessonPrice;
        this.unRefBigLessonPriceTotal = big.unRefBigLessonPriceTotal;
        this.unRefXcxCount = big.unRefXcxCount;
        this.unRefXcxFee = big.unRefXcxFee;
        this.unRefYouzanCount = big.unRefYouzanCount;
        this.unRefYouzanFee = big.unRefYouzanFee;
        this.youzanCount = big.youzanCount;
        this.youzanFee = big.youzanFee;
        this.youzanRefundFee = big.youzanRefundFee;
        this.xcxFee = big.xcxFee;
        this.xcxCount = big.xcxCount;
        this.xcxRefundFee = big.xcxRefundFee;
        this.studioId = big.studioId;
        this.skuId = big.skuId;
        this.deptId = big.deptId;

    }

    public void mergerData() {
        this.bigLessonPrice = sum(this.bigLessonPrice, this.unRefBigLessonPrice);
        this.youzanCount = sum(this.youzanCount, this.unRefYouzanCount);
        this.youzanFee = sum(this.youzanFee, this.unRefYouzanFee);
        this.xcxCount = sum(this.xcxCount, this.unRefXcxCount);


    }

    private static Float sum(Float val1, Float val2) {
        val1 = Objects.isNull(val1) ? 0f : val1;
        val2 = Objects.isNull(val2) ? 0f : val2;
        return val1 + val2;
    }

    private static Integer sum(Integer val1, Integer val2) {
        val1 = Objects.isNull(val1) ? 0 : val1;
        val2 = Objects.isNull(val2) ? 0 : val2;
        return val1 + val2;
    }

}
